From: Keir Fraser Date: Fri, 29 May 2009 08:33:06 +0000 (+0100) Subject: xend: Add serialise_pci_opts() and split_pci_opts() X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~13845 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=69cf305aa73ee4a2f6e8460ad0bf7f845a34f2a5;p=xen.git xend: Add serialise_pci_opts() and split_pci_opts() This centralises some code. Signed-off-by: Simon Horman --- diff --git a/tools/python/xen/util/pci.py b/tools/python/xen/util/pci.py index a1df4c464f..c88ad25bec 100644 --- a/tools/python/xen/util/pci.py +++ b/tools/python/xen/util/pci.py @@ -114,6 +114,12 @@ PAGE_MASK=~(PAGE_SIZE - 1) def PCI_DEVFN(slot, func): return ((((slot) & 0x1f) << 3) | ((func) & 0x07)) +def serialise_pci_opts(opts): + return reduce(lambda x, y: x+','+y, map(lambda (x, y): x+'='+y, opts)) + +def split_pci_opts(opts): + return map(lambda x: x.split('='), opts.split(',')) + def parse_hex(val): try: if isinstance(val, types.StringTypes): diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 2c75c91fcf..9d821d02fa 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -39,7 +39,7 @@ from xen.util import asserts, auxbin from xen.util.blkif import blkdev_uname_to_file, blkdev_uname_to_taptype import xen.util.xsm.xsm as security from xen.util import xsconstants -from xen.util.pci import assigned_or_requested_vslot +from xen.util.pci import assigned_or_requested_vslot, serialise_pci_opts from xen.xend import balloon, sxp, uuid, image, arch from xen.xend import XendOptions, XendNode, XendConfig @@ -739,10 +739,8 @@ class XendDomainInfo: if self.domid is not None: opts = '' - if 'opts' in new_dev and len(new_dev['opts']) > 0: - config_opts = new_dev['opts'] - config_opts = map(lambda (x, y): x+'='+y, config_opts) - opts = ',' + reduce(lambda x, y: x+','+y, config_opts) + if new_dev.has_key('opts'): + opts = ',' + serialise_pci_opts(new_dev['opts']) bdf_str = "%s:%s:%s.%s@%s%s" % (new_dev['domain'], new_dev['bus'], diff --git a/tools/python/xen/xend/server/pciif.py b/tools/python/xen/xend/server/pciif.py index 3e99e6908d..cccdc9d4f2 100644 --- a/tools/python/xen/xend/server/pciif.py +++ b/tools/python/xen/xend/server/pciif.py @@ -76,10 +76,8 @@ class PciController(DevController): func = parse_hex(pci_config.get('func', 0)) vslot = parse_hex(assigned_or_requested_vslot(pci_config)) - opts = pci_config.get('opts', '') - if len(opts) > 0: - opts = map(lambda (x, y): x+'='+y, opts) - opts = reduce(lambda x, y: x+','+y, opts) + if pci_config.has_key('opts'): + opts = serialise_pci_opts(pci_config['opts']) back['opts-%i' % pcidevid] = opts back['dev-%i' % pcidevid] = "%04x:%02x:%02x.%01x" % \ @@ -226,10 +224,7 @@ class PciController(DevController): dev_sxpr = ['dev'] for dev_key, dev_val in dev.items(): if dev_key == 'opts': - opts = [] - for opt in dev_val.split(','): - opts.append(opt.split('=')) - dev_sxpr.append(['opts', opts]) + dev_sxpr.append(['opts', split_pci_opts(dev_val)]) else: dev_sxpr.append([dev_key, dev_val]) sxpr.append(dev_sxpr)